<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta content="telephone=no,email=no,address=no" name="format-detection" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<meta name="msapplication-tap-highlight" content="no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="is_webp" content="yes" />
		<title>收货地址管理</title>
		<meta name="Keywords" content="用户中心" />
		<meta name="Description" content="用户中心" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="__TMPL__Public/css/common.css" />
		<link rel="stylesheet" href="__TMPL__Public/css/user.css" />
		<link rel="stylesheet" href="__TMPL__Public/css/public.css" />
		<style>
			.list-footer {
				background: red;
			}
			
			.list-footer a {
				color: #fff;
			}
			
			#add-address-div {
				display: none;
			}
			
			.addressmone1 .save_btn.ok .btn {
				background: red;
			}
			input{font: 13.3333px Arial;}    
		</style>
	</head>

	<body>
		<php>
			$get_moblie_address=get_moblie_address(); $all_province=getProvinceList('-10'); $all_city=getCityList('-10'); $all_district=getDistrictList('-10');
		</php>

		<div>
			<?php
				$agent = $_SERVER['HTTP_USER_AGENT'];
				if(strpos($agent,"Html5Plus") === false){
			?>
			<header>
				<div class="header">
					<div class="header-left">
						<a class="sb-back" href="{:U('user/center')}" title="返回"></a>
					</div>
					<div class="header-middle">收货地址管理</div>
					<div class="header-right">
						<aside class="show-menu-btn">
							<div id="show_more" class="show-menu">
								<a href="javascript:;"></a>
							</div>
						</aside>
					</div>
				</div>
			</header>
			<?php
				}
			?>
			<mtc_include file="Public:right_nav" />
			<div class="address-box">
				<div class="tablelist-append" id="tablelist_append">
					<div class="product single_item info"></div>
						<a href="javascript:;" class="get_more">
					</a>
				</div>
				<div style="width: 100%; height: 50px;"></div>
				<div class="list-footer">
					<a href="javascript:add()">添加新地址</a>
				</div>

			</div>
		</div>
		<div id="edit-address-div">

		</div>
		<div class="addressmone1" id="add-address-div">
			<form id="UserAddressModel" class="form-horizontal" name="UserAddressModel">
				<input type="hidden" name="address_id" id="address_id" value="0" />
				<div class="form-group-box">
					<!-- 收货人 -->
					<span id="consignee_box">
						<div class="form-group form-group-spe">
						<dl>
						<dt>
						<span>收货人：</span>
					</dt>
					<dd>
						<div class="form-control-box">
							<input type="text" id="useraddressmodel-consignee" class="consignee" placeholder="你的姓名">
						</div>
					</dd>
					</dl>
				</div>
				<div class="invalid"></div>
				</span>
				<span id="mobile_box">
					<!-- 联系电话 -->
					<div class="form-group form-group-spe">
					<dl><dt><span>手机号码：</span></dt>
					<dd>
						<div class="form-control-box">
							<input type="number" id="useraddressmodel-mobile" class="mobile" placeholder="你的手机号">
						</div>
					</dd>
				</dl>
		</div>
		<div class="invalid"></div>
		</span>
		<span id="region_code_box">
			<!-- 收货地址 -->
			<div class="form-group form-group-spe">
			<dl>
				<dt>
					<span>收货地址：</span>
				</dt>
				<dd>
				<div class="form-control-box">
					<a href="javascript:void(0)" class="address-btn"></a>
					<div class="region-chooser-container region-chooser">
						<div class="region-chooser-selected" id="J_Address">
							<div class="region">
								<font color="#999">请选择配送区域<i class="iconfont"></i></font>
							</div>
						</div>
					</div>
					<input type="hidden" id="add_province_id" value="" />
					<input type="hidden" id="add_city_id" value="" />
					<input type="hidden" id="add_district_id" value="" />
				</div>
			</dd>
		</dl>
		</div>
		<div class="invalid"></div>
		</span>
		<!-- 详细地址 s-->
		<span id="address_detail_box">
		<div class="form-group form-group-spe">
		<dl>
			<dt>
				<span>详细地址：</span>
			</dt>
		<dd>
			<div class="form-control-box">
				<textarea id="address_detail" class="address_detail" rows="2" placeholder="如街道，楼层，门牌号等"></textarea>
			</div>
		</dd>
		</dl>
		</div>
		<div class="invalid"></div>
		</span>

		</div>

		<div class="save_btn ok">
			<a class="btn" href="javascript:void(0);" id="btn_validate" style="width: 44%; margin-left: 5%;">确定</a>
			<a class="closebtn" href="javascript:void(0);" id="close_adr_btn">取消</a>
		</div>

		</form>
		</div>
		<!-- 底部 _end-->
		<section class="mask-div"></section>
		<script type="text/javascript" src="/themes/wnsc_moblie/newMobile/User/js/area/jquery.min.js"></script>
		<script type="text/javascript" src="__TMPL__Public/js/common.js"></script>
		<link rel="stylesheet" href="/themes/wnsc_moblie/newMobile/User/js/area/ydui.css" />
		<script type="text/javascript">
			var citys = <php>echo $get_moblie_address;</php>;
			var all_province = <php>echo $all_province;</php>;
			var all_city = <php>echo $all_city;</php>;
			var all_district = <php>echo $all_district;</php>;
		</script>
		<script src="/themes/wnsc_moblie/newMobile/User/js/area/ydui.flexible.js"></script>
		<script type="text/javascript" src="/themes/wnsc_moblie/newMobile/User/js/area/ydui.citys.js"></script>
		<script type="text/javascript" src="/themes/wnsc_moblie/newMobile/User/js/area/ydui.js"></script>
		<script src="/themes/wnsc_moblie/newMobile/User/login/js/mobile/layer.js"></script>
		<script type="application/javascript" src="__TMPL__Public/js/jquery.more.js"></script>
		<php>if($_GET['noaddess']==1){</php>
			<script type="text/javascript">
				$(function(){
					add();
				})
			</script>
		<php>}</php>
		<php>
			$shiji_url=U('user/address',array('type'=>$_GET['type'],'rec_id'=>$_GET['rec_id'],'recommend_shop_id'=>$_GET['recommend_shop_id'],'recommend_shop_num'=>$_GET['recommend_shop_num']));
		</php>
		<script type="text/javascript">
			var province_name='';
			var city_name='';
			var district_name='';
			function edit(id) {
				$.ajax({
					type: 'get',
					url: '/user/addressInsert',
					data: {
						id: id
					},
					dataType: 'json',
					success: function(res) {
						$('#useraddressmodel-consignee').val(res.data.consigner);
						$('#useraddressmodel-mobile').val(res.data.mobile);
						$('#add_province_id').val(res.data.province);
						$('#add_city_id').val(res.data.city);
						$('#add_district_id').val(res.data.district);
						$('#address_detail').val(res.data.address);
						$('#address_id').val(id);
						$('.region font').html(res.data.province_name+'&nbsp;'+res.data.city_name+'&nbsp;'+res.data.district_name+'<i class="iconfont"></i>')
						$('.address-box').hide();
						$('#add-address-div').show();
						province_name=res.data.province_name;
						city_name=res.data.city_name;
						district_name=res.data.district_name;
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {
						showErrorMsg('网络失败，请刷新页面后重试');
					}
				})
				
			}
			/**
			 * 地区
			 */
			! function() {
				var $target = $('#J_Address');
				
				$target.citySelect({
		            provance: province_name,
		            city: city_name,
		            area: district_name
		        });
				$target.on('click', function(event) {
					event.stopPropagation();
					$target.citySelect('open');
				});

				$target.on('done.ydui.cityselect', function(ret) {
					$('.region').html(ret.provance + ' ' + ret.city + ' ' + ret.area+'<i class="iconfont"></i>');
					$.each(all_province, function(i, value) {
						if(value.province_name == ret.provance) {
							$('#add_province_id').val(value.province_id);
						}
					});
					$.each(all_city, function(i, value) {
						if(value.city_name == ret.city) {
							$('#add_city_id').val(value.city_id);
						}
					});
					$.each(all_district, function(i, value) {
						if(value.district_name == ret.area) {
							$('#add_district_id').val(value.district_id);
						}
					});

				});
			}();
		</script>
		<script type="text/javascript">
		
				var url = "{:U('user/get_addrsss',array('type'=>$_GET['type']))}";
				$(function() {
					$('#tablelist_append').more({
						'address': url,
						'more':"<div class='jiazai'><em></em><span>亲，到底咯！</span><em></em></div>"
					});
				
					$('#close_adr_btn').click(function(){
						$('#useraddressmodel-consignee').val('');
						$('#useraddressmodel-mobile').val('');
						$('#add_province_id').val('');
						$('#add_city_id').val('');
						$('#add_district_id').val('');
						$('#address_detail').val('');
						$('#address_id').val(0);
						$('.region').html('<font color="#999">请选择配送区域<i class="iconfont"></i></font>')
						$('.address-box').show();
						$('#add-address-div').hide();
					})
				
					$("body").on("click",".add_selected", function() { 
						var address_id=$(this).attr('data-address_id')
						$.ajax({
								type: 'post',
								url: '/user/addressisdefault',
								data: {
									address_id: address_id
								},
								dataType: 'json',
								success: function(res) {
									layer.open({
									    content: res.message
									    ,skin: 'msg'
									    ,time: 2 //2秒后自动关闭
									 });
									
									if(res.code == 1) {
										setTimeout("window.location.href='{$shiji_url}'",1000);
									}
			
								},
								error: function(XMLHttpRequest, textStatus, errorThrown) {
									showErrorMsg('网络失败，请刷新页面后重试');
								}
							})
					})
					
					$("body").on("click",".queren", function() { 
						var address_id=$(this).attr('data')
						$.ajax({
								type: 'post',
								url: '/user/addressisdefault',
								data: {
									address_id: address_id
								},
								dataType: 'json',
								success: function(res) {
									if(res.code == 1) {
										window.location.href="/pay/paymentOrder";
									}
			
								},
								error: function(XMLHttpRequest, textStatus, errorThrown) {
									showErrorMsg('网络失败，请刷新页面后重试');
								}
							})
					})
					<php>
						$url=U('pay/lipin',array('rec_id'=>$_GET['rec_id'],'recommend_shop_id'=>$_GET['recommend_shop_id'],'recommend_shop_num'=>$_GET['recommend_shop_num']));
					</php>
					$("body").on("click",".queren2", function() { 
						var address_id=$(this).attr('data')
						var uurl='{$url}';
						$.ajax({
								type: 'post',
								url: '/user/addressisdefault',
								data: {
									address_id: address_id
								},
								dataType: 'json',
								success: function(res) {
									if(res.code == 1) {
										window.location.href=uurl;
									}
			
								},
								error: function(XMLHttpRequest, textStatus, errorThrown) {
									showErrorMsg('网络失败，请刷新页面后重试');
								}
							})
					})
					$("body").on("click",".address-delete", function() { 
						var address_id=$(this).attr('data-address_id')
						$.ajax({
								type: 'post',
								url: '/user/addressdelete',
								data: {
									address_id: address_id
								},
								dataType: 'json',
								success: function(res) {
									layer.open({
									    content: res.message
									    ,skin: 'msg'
									    ,time: 2 //2秒后自动关闭
									 });
									
									if(res.code == 1) {
										setTimeout('location.reload();',1000);
									}
			
								},
								error: function(XMLHttpRequest, textStatus, errorThrown) {
									showErrorMsg('网络失败，请刷新页面后重试');
								}
							})
					})
					$('#btn_validate').click(function(){
						var consignee=$('#useraddressmodel-consignee').val();
						var mobile=$('#useraddressmodel-mobile').val();
						var add_province_id=$('#add_province_id').val();
						var add_city_id=$('#add_city_id').val();
						var add_district_id=$('#add_district_id').val();
						var address_detail=$('#address_detail').val();
						var address_id=$('#address_id').val();
						if(consignee==''||mobile==''||add_province_id==''||add_city_id==''||add_district_id==''||address_detail==''){
							layer.open({
							    content: '请填写完整！'
							    ,skin: 'msg'
							    ,time: 2 //2秒后自动关闭
							  });
							 return false;
						}
						if(checkMobile(mobile)){
							$.ajax({
								type: 'post',
								url: '/user/addressInsert',
								data: {
									consignee: consignee,
									mobile: mobile,
									add_province_id: add_province_id,
									add_city_id: add_city_id,
									add_district_id: add_district_id,
									address_detail: address_detail,
									address_id:address_id
								},
								dataType: 'json',
								success: function(res) {
									layer.open({
									    content: res.message
									    ,skin: 'msg'
									    ,time: 2 //2秒后自动关闭
									 });
									
									if(res.code == 1) {
										setTimeout("window.location.href='{$shiji_url}'",1000);
									}
			
								},
								error: function(XMLHttpRequest, textStatus, errorThrown) {
									showErrorMsg('网络失败，请刷新页面后重试');
								}
							})
						}else{
							layer.open({
							    content: '请填写正确的手机号！'
							    ,skin: 'msg'
							    ,time: 2 //2秒后自动关闭
							  });
							 return false;
						}
						
					});
				});
			
			
			function checkMobile(tel) {
			    var reg = /(^1[3|4|5|7|8][0-9]{9}$)/;
			    if (reg.test(tel)) {
			        return true;
			    }else{
			        return false;
			    };
			}
			function add() {
				$('.address-box').hide();
				$('#add-address-div').show();
			}
			
		</script>
	</body>

</html>